package com.android.boncen.commonFrame.user;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.android.boncen.commonFrame.R;

/***
 * //       记录页面左上角个人中心，那里面显示最近血糖情况（过高过低正常的次数），
 //        2. 以及我的医生（显示我收藏过的医生）
 //        3.血糖历史
 //        4.咨询记录
 */
public class UserInfoActivity extends FragmentActivity implements View.OnClickListener {
    private ImageButton ibBack;
    private TextView tvTitle;

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        findView();
        Adapter adapter = new Adapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }

    private void findView() {
        ibBack = (ImageButton) findViewById(R.id.ib_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tabLayout = (TabLayout)findViewById(R.id.tablayout);
        viewPager = (ViewPager) findViewById(R.id.knowledge_viewpage);
        ibBack.setOnClickListener(this);
        ibBack.setVisibility(View.VISIBLE);
        tvTitle.setText("个人中心");
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ib_back:
                finish();
                break;
        }
    }

    public class Adapter extends FragmentPagerAdapter {

        public Adapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment fragment = null;
            switch (position)
            {
                case 0:
//                    记录页面左上角个人中心，那里面显示最近血糖情况（过高过低正常的次数），
                    fragment = new SugarSizeFragment();
                    break;
                case 1:
//                    2. 以及我的医生（显示我收藏过的医生）
                    fragment = new CollectionFragment();
                    break;
                case 2:
//                    3.血糖历史
                    fragment = new GlucoseHistoryFragment();
                    break;
                case 3:
//                      4.咨询记录
                    fragment = new ConsultationFragment();
                    break;
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            String title = "";
            switch (position)
            {
                case 0:
//                    记录页面左上角个人中心，那里面显示最近血糖情况（过高过低正常的次数），
                    title="血糖情况";
                    break;
                case 1:
//                    2. 以及我的医生（显示我收藏过的医生）
                    title="我的医生";
                    break;
                case 2:
//                    3.血糖历史
                    title="血糖历史";
                    break;
                case 3:
//                      4.咨询记录
                    title="咨询记录";
                    break;
            }
            return title;

        }
    }

}
